package com.gitee.wsl.time.chinese

import kotlinx.datetime.LocalDate
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue


class ChineseDateTest {
    @Test
    fun chineseDateTest() {
        var date = ChineseDate(LocalDate.parse("2020-01-25"))
        assertEquals("2020-01-25 00:00:00", date.gregorianDate.toString())
        assertEquals(2020, date.chineseYear)

        assertEquals(1, date.month)
        assertEquals("一月", date.chineseMonth)
        assertEquals("正月", date.chineseMonthName)


        assertEquals(1, date.day)
        assertEquals("初一", date.chineseDay)

        assertEquals("庚子", date.cyclical)
        assertEquals("鼠", date.chineseZodiac)
        assertEquals("春节", date.festivals)
        assertEquals("庚子鼠年 正月初一", date.toString())

        date = ChineseDate(LocalDate.parse("2020-01-14"))
        assertEquals("己亥猪年 腊月二十", date.toString())
        date = ChineseDate(LocalDate.parse("2020-01-24"))
        assertEquals("己亥猪年 腊月三十", date.toString())

        assertEquals("2019-12-30", date.toStringNormal())
    }

    @Test
    fun toStringNormalTest() {
        val date = ChineseDate(LocalDate.parse("2020-03-1"))
        assertEquals("2020-02-08", date.toStringNormal())
    }

    @Test
    fun parseTest() {
        var date = ChineseDate(LocalDate.parse("1996-07-14"))
        assertEquals("丙子鼠年 五月廿九", date.toString())

        date = ChineseDate(LocalDate.parse("1996-07-15"))
        assertEquals("丙子鼠年 五月三十", date.toString())
    }


    val chineseMonthTest: Unit
        get() {
            var chineseDate = ChineseDate(2020, 6, 15)
            assertEquals("2020-08-04 00:00:00", chineseDate.gregorianDate.toString())
            assertEquals("六月", chineseDate.chineseMonth)

            chineseDate = ChineseDate(2020, 4, 15)
            assertEquals("2020-06-06 00:00:00", chineseDate.gregorianDate.toString())
            assertEquals("闰四月", chineseDate.chineseMonth)

            chineseDate = ChineseDate(2020, 5, 15)
            assertEquals("2020-07-05 00:00:00", chineseDate.gregorianDate.toString())
            assertEquals("五月", chineseDate.chineseMonth)
        }

   
    val festivalsTest: Unit
        get() {
            // issue#I1XHSF@Gitee，2023-01-20对应农历腊月29，非除夕
            val chineseDate = ChineseDate(LocalDate.parse("2023-01-20"))
            assertTrue(chineseDate.festivals.isEmpty())
        }

    @Test
    fun dateTest() {
        // 修复这两个日期不正确的问题
        // 问题出在计算与1900-01-31相差天数的问题上了，相差天数非整天
        var date = ChineseDate(LocalDate.parse("1991-09-14"))
        assertEquals("辛未羊年 八月初七", date.toString())
        date = ChineseDate(LocalDate.parse("1991-09-15"))
        assertEquals("辛未羊年 八月初八", date.toString())
    }

    @Test
    fun dateTest2() {
        val date = ChineseDate(LocalDate.parse("2020-10-19"))
        assertEquals("庚子鼠年 九月初三", date.toString())
    }

    @Test
    fun dateTest2_2() {
        val date = ChineseDate(LocalDate.parse("2020-07-20"))
        assertEquals("庚子鼠年 五月三十", date.toString())
    }

    @Test
    fun dateTest3() {
        // 初一，offset为0测试
        val date = ChineseDate(LocalDate.parse("2099-03-22"))
        assertEquals("己未羊年 闰二月初一", date.toString())
    }

    @Test
    fun leapMonthTest() {
        val c1 = ChineseDate(LocalDate.parse("2028-05-28"))
        val c2 = ChineseDate(LocalDate.parse("2028-06-27"))

        assertEquals("戊申猴年 五月初五", c1.toString())
        assertEquals("戊申猴年 闰五月初五", c2.toString())
    }

    
    val chineseMonthTest2: Unit
        get() {
            //https://github.com/chinabugotech/hutool/issues/2112
            val springFestival = ChineseDate(LocalDate.parse("2022-02-01"))
            val chineseMonth = springFestival.chineseMonth
            assertEquals("一月", chineseMonth)
        }

    @Test
    fun day19700101Test() {
        // https://gitee.com/chinabugotech/hutool/issues/I4UTPK
        var date = LocalDate.parse("1970-01-01")
        var chineseDate = ChineseDate(date)
        assertEquals("己酉鸡年 冬月廿四", chineseDate.toString())

        date = LocalDate.parse("1970-01-02")
        chineseDate = ChineseDate(date)
        assertEquals("己酉鸡年 冬月廿五", chineseDate.toString())

        date = LocalDate.parse("1970-01-03")
        chineseDate = ChineseDate(date)
        assertEquals("己酉鸡年 冬月廿六", chineseDate.toString())
    }

    @Test
    fun day19000101Test() {
        // 1900-01-31之前不支持
        val date = LocalDate.parse("1900-01-31")
        val chineseDate = ChineseDate(date)
        assertEquals("庚子鼠年 正月初一", chineseDate.toString())
    }

    val gregorianDateTest: Unit
        get() {
            // https://gitee.com/chinabugotech/hutool/issues/I4ZSGJ
            var chineseDate = ChineseDate(1998, 5, 1)
            assertEquals("1998-06-24 00:00:00", chineseDate.gregorianDate.toString())

            chineseDate = ChineseDate(1998, 5, 1, false)
            assertEquals("1998-05-26 00:00:00", chineseDate.gregorianDate.toString())
        }
}
